﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Threading;
using Microsoft.SharePoint.Publishing.WebControls;

namespace ISolutions.SharePoint.Mui.Controls
{
    /// <summary>
    /// MUI Rich Text Field. Renders in Display Mode the content for the current user language.
    /// 
    /// by David Schneider, isolutions AG, http://blog.sharepoint.ch
    /// </summary>
    [ToolboxItemAttribute(false)]
    public class RichTextField : TabbedMuiControl
    {
        //
        // Summary:
        //     Gets or sets the HtmlEditor style sheet prefix.
        [Browsable(true)]
        [DefaultValue(typeof(String), "ms-rte")]
        public string PrefixStyleSheet
        {
            get;
            set;
        }

        [Browsable(true)]
        [DefaultValue("")]
        public bool? HasInitialFocus
        {
            get;
            set;
        }

        [Browsable(true)]
        [DefaultValue("")]
        public string MinimumEditHeight
        {
            get;
            set;
        }        

        /// <summary>
        /// Creates a Rich HTML field and sets the PrefixStyleSheet if not null
        /// </summary>
        /// <returns>
        /// A control instance used to edit the field value for one language.
        /// </returns>
        protected override FieldMetadata CreateEditControl()
        {
            RichHtmlField editControl = new RichHtmlField();
            if (PrefixStyleSheet != null)
            {
                editControl.PrefixStyleSheet = this.PrefixStyleSheet;
            }

            if (MinimumEditHeight != null)
            {
                editControl.MinimumEditHeight = this.MinimumEditHeight;
            }

            if (HasInitialFocus.HasValue)
            {
                editControl.HasInitialFocus = this.HasInitialFocus;
            }
            return editControl;
        }       
    }
}
